package cn.wizzer.app.user.modules.service.impl;

import cn.wizzer.app.user.modules.models.UserFocus;
import cn.wizzer.app.user.modules.services.UserFocusService;
import cn.wizzer.app.user.modules.services.UserService;
import cn.wizzer.framework.base.service.BaseServiceImpl;
import cn.wizzer.framework.page.Pagination;
import com.alibaba.dubbo.config.annotation.Service;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

@IocBean(args = {"refer:dao"})
@Service(interfaceClass = UserFocusService.class)
public class UserFocusServiceImpl extends BaseServiceImpl<UserFocus> implements UserFocusService {

    public UserFocusServiceImpl(Dao dao) {
        super(dao);
    }

    @Inject
    private UserService userService;

    @Override
    public Pagination listPage(Integer pageNumber, int pageSize, String userId) {
        Sql sql = Sqls.create("select u.id,u.headPicture,u.nickName,u.sign,u.certified from user u");
        Sql countSql = Sqls.create("select count(1) from user u");
        Sql joinSql = Sqls.create("left join user_focus uf on u.id = uf.anchorId " +
                "where uf.userId = @userId " +
                "and uf.delFlag = 0 ");
        joinSql.setParam("userId", userId);
        sql.appendSourceSql(joinSql.toString());
        sql.appendSourceSql("order by uf.opAt desc");
        countSql.appendSourceSql(joinSql.toString());
        return  userService.listPage(pageNumber, pageSize, sql, countSql);
    }
}
